-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
pkg/tinydtls: Implement sock_aux_local #14706
Conversation
Rebased on top of #14704 |
sock_aux_local
All dependencies are merged. Please rebase to current master. |
While the code is simple enough, do you have a suggestion how to test this? |
I applied the following patch diff --git a/examples/dtls-sock/Makefile b/examples/dtls-sock/Makefile
index 8861948702..1a15299175 100644
--- a/examples/dtls-sock/Makefile
+++ b/examples/dtls-sock/Makefile
@@ -23,6 +23,8 @@ USEPKG += tinydtls
# Pull in sock APIs
USEMODULE += sock_dtls
USEMODULE += sock_udp
+USEMODULE += sock_aux_local
+USEMODULE += sock_util
# tinydtls needs crypto secure PRNG
USEMODULE += prng_sha1prng
diff --git a/examples/dtls-sock/dtls-client.c b/examples/dtls-sock/dtls-client.c
index c5cb43a894..093cf24f9d 100644
--- a/examples/dtls-sock/dtls-client.c
+++ b/examples/dtls-sock/dtls-client.c
@@ -20,6 +20,7 @@
#include "net/sock/udp.h"
#include "net/sock/dtls.h"
+#include "net/sock/util.h"
#include "net/ipv6/addr.h"
#include "net/credman.h"
@@ -76,6 +77,7 @@ static int client_send(char *addr_str, char *data, size_t datalen)
sock_dtls_session_t session;
sock_udp_ep_t remote = SOCK_IPV6_EP_ANY;
sock_udp_ep_t local = SOCK_IPV6_EP_ANY;
+ sock_dtls_aux_rx_t aux = { .flags = SOCK_AUX_GET_LOCAL };
local.port = 12345;
remote.port = DTLS_DEFAULT_PORT;
uint8_t buf[DTLS_HANDSHAKE_BUFSIZE];
@@ -128,8 +130,8 @@ static int client_send(char *addr_str, char *data, size_t datalen)
return res;
}
- res = sock_dtls_recv(&dtls_sock, &session, buf, sizeof(buf),
- SOCK_NO_TIMEOUT);
+ res = sock_dtls_recv_aux(&dtls_sock, &session, buf, sizeof(buf),
+ SOCK_NO_TIMEOUT, &aux);
if (res != -SOCK_DTLS_HANDSHAKE) {
printf("Error creating session: %d\n", (int)res);
sock_dtls_close(&dtls_sock);
@@ -137,6 +139,13 @@ static int client_send(char *addr_str, char *data, size_t datalen)
return -1;
}
printf("Connection to server successful\n");
+ if (!(aux.flags & SOCK_AUX_GET_LOCAL)) {
+ uint16_t port;
+ char addr[IPV6_ADDR_MAX_STR_LEN];
+
+ sock_udp_ep_fmt(&aux.local, addr, &port);
+ printf("on local end-point [%s]:%u\n", addr, port);
+ }
if (sock_dtls_send(&dtls_sock, &session, data, datalen, 0) < 0) {
puts("Error sending data");
@@ -145,10 +154,18 @@ static int client_send(char *addr_str, char *data, size_t datalen)
printf("Sent DTLS message\n");
uint8_t rcv[512];
- if ((res = sock_dtls_recv(&dtls_sock, &session, rcv, sizeof(rcv),
- SOCK_NO_TIMEOUT)) >= 0) {
+ aux.flags |= SOCK_AUX_GET_LOCAL;
+ if ((res = sock_dtls_recv_aux(&dtls_sock, &session, rcv, sizeof(rcv),
+ SOCK_NO_TIMEOUT, &aux)) >= 0) {
printf("Received %d bytes: \"%.*s\"\n", (int)res, (int)res,
(char *)rcv);
+ if (!(aux.flags & SOCK_AUX_GET_LOCAL)) {
+ uint16_t port;
+ char addr[IPV6_ADDR_MAX_STR_LEN];
+
+ sock_udp_ep_fmt(&aux.local, addr, &port);
+ printf("on local end-point [%s]:%u\n", addr, port);
+ }
}
}
And I get the expected output:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
Thanks for reviewing and especially for taking the time to adapt the example application to properly test this! |
With pleasure :-) |
Contribution description
This PR adds the implementation of the
sock_aux_local
for tinydtls, that provides access to the local address via the extended SOCK API of #14703.Testing procedure
No testing application provided :-/
Issues/PRs references
Depends on